package com.thread.demo8;

public class ReadThread extends Thread{
	

	@Override
	public void run() {
		while (!Thread.currentThread().isInterrupted()) {
			if(ready){
				System.out.println("====="+(num+num));
			}
			System.out.println("read thread...");
		}
	}
	
	public static class WriteThread extends Thread{
		@Override
		public void run() {
			num = 2;
			ready = true;
			System.out.println("write thread set over...");
		}
	}
	
	private static  int num = 0;
	private static  boolean ready = false;
	
	public static void main(String[] args) throws InterruptedException {
		ReadThread rt = new ReadThread();
		rt.start();
//		Thread.sleep(100);
		WriteThread wt = new WriteThread();
		wt.start();
		
		Thread.sleep(1000);
		rt.interrupt();
		System.out.println("main exit");
		ready = true;
//		
//		for(int i=0;i<10;i++){
//			if(ready){
//				System.out.println("====="+(num+num));
//			}
//			System.out.println("read thread...");
//		}
//		while (!Thread.currentThread().isInterrupted()) {
//		}
		
	}
	
}
